/*************************************************************************
 *
 *  Copyright (C) 2013 Florian Dang <florian.coin@gmail.com>
 *
 *  This file is part of NatusVerse.
 *
 *  NatusVerse is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  NatusVerse is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with NatusVerse.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************/

#ifndef INC_LIFE_CELL_H_
#define INC_LIFE_CELL_H_

/*!
 * \file        cell.h
 * \brief       cell description for Conway's Game of Life
 * \author      Florian Dang
 * \date        2013
 */

#include <stdio.h>
#include <cassert>

#include "graphics/graphics.h"
#include "graphics/color.h"

namespace life
{
//! Cell class
/*!
  Cell for Conway's Game of Life
*/
class Cell
{
	public:
		typedef graphics::Graphics Window;
		typedef Window::t_point t_point;
		typedef color::Color Color;

		enum State
		{
			kDead    = 0,
			kAlive   = 1
		};

		//! default constructor
		Cell() : state_(kDead), x_(0), y_(0), color_(color::black) {}

		//! classic constructor
		Cell(State state0, int x0, int y0, Color color0)
			: state_(state0), x_(x0), y_(y0), color_(color0) {}

		inline State state() const { return state_; }
		inline int x() const { return x_; }
		inline int y() const { return y_; }
		inline Color color() const { return color_; }

		void set_state(State state0)
		{
			state_ = state0;
			set_color();
		}

		void set_x(int x0) { x_ = x0; }
		void set_y(int y0) { y_ = y0; }
		void set_color(Color color0) { color_ = color0; }
		void set_color()
		{
			switch(state_)
			{
				case Cell::kDead:
				{
					color_ = color::black;
					break;
				}
				case Cell::kAlive:
				{
					color_ = color::lightgreen;
					break;
				}
				default:
				{
					assert(false);
				}
			}
		}

		void Display(Window win,
					t_point down_left,
					t_point up_right) const;

		void Print() const;

		//! destructor
		~Cell() {}

	private:
		State state_;   /*!< Cell state */
		int   x_;       /*!< x coordinate */
		int   y_;       /*!< y coordinate */
		Color color_;   /*!< Cell color */
};
} // end namespace life
#endif  // INC_LIFE_CELL_H_
